package com.example.a14110100409.yuejiandemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.activity.UserTieziActivity;
import com.example.a14110100409.yuejiandemo.config.Config;
import com.example.a14110100409.yuejiandemo.javabean.Club;
import com.example.a14110100409.yuejiandemo.javabean.UserShaitu;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by owner on 2017/10/12.
 */

public class TieziListAdapter extends RecyclerView.Adapter {
    private Context mContext;

    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局
    private String user_name;

    public TieziListAdapter(Context mContext, List mDataList ,String user_name) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        this.user_name = user_name;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(mContext).inflate(R.layout.cardview_tiezilist, parent, false);
        return new TieziListAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final UserShaitu entity = (UserShaitu) mDataList.get(position);

        if (null == entity)
            return;
        TieziListAdapter.ViewHolder viewHolder = (TieziListAdapter.ViewHolder) holder;
        viewHolder.user_shaitu_name.setText(user_name);
        viewHolder.user_shaitu_time.setText(entity.getUpdate_time());
        viewHolder.user_shaitu_title.setText(entity.getTitle());
        viewHolder.user_shaitu_pic.setImageResource(R.drawable.tx);
        if(entity.getThumb0().equals("")){
            ((ViewHolder) viewHolder).user_shaitu_photo1.setImageResource(R.drawable.dog_1);
        }else {
            String address1="http://172.24.10.175/workout/Uploads/"+entity.getThumb0();
            Picasso.with(mContext).load(address1).into(viewHolder.user_shaitu_photo1);
        }

        if(entity.getThumb1().equals("")){
            ((ViewHolder) viewHolder).user_shaitu_photo2.setImageResource(R.drawable.dog);
        }else {
            String address1="http://172.24.10.175/workout/Uploads/"+entity.getThumb1();
            Picasso.with(mContext).load(address1).into(viewHolder.user_shaitu_photo2);
        }

        if(entity.getThumb2().equals("")){
            ((ViewHolder) viewHolder).user_shaitu_photo3.setImageResource(R.drawable.tx);
        }else {
            String address1="http://172.24.10.175/workout/Uploads/"+entity.getThumb2();
            Picasso.with(mContext).load(address1).into(viewHolder.user_shaitu_photo3);
        }



       /* String address2="http://172.24.10.175/workout/Uploads/"+entity.getThumb1();
        if(!entity.getThumb1().equals("")){
            Picasso.with(mContext).load(address2).into(viewHolder.user_shaitu_photo2);
        }
        String address3="http://172.24.10.175/workout/Uploads/"+entity.getThumb2();
        if(!entity.getThumb2().equals("")){
            Picasso.with(mContext).load(address3).into(viewHolder.user_shaitu_photo3);
        }*/
        /*String address="http://172.24.10.175/workout/Uploads/"+entity.getThumb();
        if(!entity.getThumb().equals("")){
            Picasso.with(mContext).load(address).into(viewHolder.coachPhoto);
        }*/
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView user_shaitu_pic,user_shaitu_photo1,user_shaitu_photo2,user_shaitu_photo3;
        TextView user_shaitu_name,user_shaitu_time,user_shaitu_title;

        public ViewHolder(View itemView) {
            super(itemView);
            user_shaitu_pic = (ImageView) itemView.findViewById(R.id.user_shaitu_pic);
            user_shaitu_photo1 = (ImageView) itemView.findViewById(R.id.user_shaitu_photo1);
            user_shaitu_photo2 = (ImageView) itemView.findViewById(R.id.user_shaitu_photo2);
            user_shaitu_photo3 = (ImageView) itemView.findViewById(R.id.user_shaitu_photo3);
            user_shaitu_name = (TextView) itemView.findViewById(R.id.user_shaitu_name);
            user_shaitu_time = (TextView) itemView.findViewById(R.id.user_shaitu_time);
            user_shaitu_title = (TextView) itemView.findViewById(R.id.user_shaitu_title);
        }
    }
}
